//增加点击率
function mm_hits(objurl,objid)
{
	var urlPar="nid=" + objid +"&random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/news/hits/",
	data: urlPar,
	success: function(response){
		//alert(response);
		var tarr=response.split("|");
		if(tarr.length>1){
			//document.getElementById("spantitle").innerText=tarr[1];
			document.getElementById("spanhits").innerText=tarr[0];
		}else{
			document.getElementById("spanhits").innerText=response;
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//增加参考资料点击率
function mm_articlehits(objurl,objid)
{
	var urlPar="aid=" + objid +"&random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/kczy/hits/",
	data: urlPar,
	success: function(response){
		var tarr=response.split("|");
		if(tarr.length>1){
			//document.getElementById("spantitle").innerText=tarr[1];
			document.getElementById("spanhits").innerText=tarr[0];
		}else{
			document.getElementById("spanhits").innerText=response;
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//添加选修课
function mm_addxx(objurl,pid)
{
	if(confirm("您确认添加吗？"))
	{
		var urlPar="pid="+pid +"&random=" +Math.random();	
		$.ajax({
		type: "GET",
		url: objurl+"/course/addxx",
		data: urlPar,
		success: function(response){			
			if(response>0){
				alert("添加成功！");		
			}
			else{
				alert("添加失败，该课程已经是必修课或选修课，或您没有权限添加本课程！");
			}
		},
		error:function(data)
		{
			//alert(data.responseText);
		}
	  });
   }
}
/*
分页
*/
function gethtml(objpager,pnum,rcount,psize,objurl,objtid,objaction){
	if(pnum<1)pnum=1;
	var pcount=rcount%psize==0?rcount/psize:Math.floor(rcount/psize)+1;
	var pagediv=document.getElementById("divpager");
	var pageHtml="";
	var goHtml=" 跳转到<input name=\"txtgo\" maxlength=\"2\" type=\"text\" class=\"fanye_kuang\">页<a href=\"#\" class=\"12jh\" onclick=\"goPageNumber(this,"+objtid+",'"+objurl+"','"+objaction+"');\" style=\"text-decoration: none;\"><strong>GO</strong></a>";
	if(parseInt(pcount)>1){
		if(pcount<=pnum){
			pageHtml="当前第"+pnum+"页/共"+pcount+"页 <a href=\"#\" class=\"12hui_\" onclick=\"mm_program("+(parseInt(objpager)-1)+","+objtid+",'"+objurl+"','"+objaction+"')\">上一页</a>  <a class=\"12hui_\">下一页</a> "+goHtml;
		}else if(pnum==1){
			pageHtml="当前第"+pnum+"页/共"+pcount+"页 <a class=\"12hui_\">上一页</a> <a href=\"#\" class=\"12hui_\" onclick=\"mm_program("+(parseInt(objpager)+1)+","+objtid+",'"+objurl+"','"+objaction+"')\">下一页</a> "+goHtml;
		}else{
			pageHtml="当前第"+pnum+"页/共"+pcount+"页 <a href=\"#\" class=\"12hui_\" onclick=\"mm_program("+(parseInt(objpager)-1)+","+objtid+",'"+objurl+"','"+objaction+"')\">上一页</a> <a href=\"#\" class=\"12hui_\" onclick=\"mm_program("+(parseInt(objpager)+1)+","+objtid+",'"+objurl+"','"+objaction+"')\">下一页</a> "+goHtml;
		}
		pagediv.innerHTML=pageHtml;
	}else{
		pagediv.innerHTML="当前第1页/共1页 <a href='#' class=\"12hui_\">上一页</a> <a href='#' class=\"12hui_\">下一页</a> "+goHtml;
	}
}
/*
Go导航页
*/
function goPageNumber(objGo,objtid,objurl,objaction){
	var pnum=objGo.previousSibling.previousSibling.value;
	if(isNaN(parseInt(pnum))){
		alert("导般页码为整型数字");
	}else{
		objpager=parseInt(pnum);
		if(objpager>0){
			mm_program(objpager,objtid,objurl,objaction);
		}else{
			alert("导般页码不能少于1");
		}
	}
}
/*
加载作业数据
*/
function mm_program(objpager,objtid,objurl,objaction){
	document.getElementById("ul_program").innerHTML="正在加载数据请稍候...";
	var urlPar="tid=" + objtid + "&p=" + objpager +"&random=" +Math.random();
	var tmpaction=document.getElementById("hfaction").value;
	if(tmpaction!=""){
		objaction=tmpaction;
	}
	$.ajax({
	type: "GET",
	url: objurl+"/course/"+objaction+"/",
	data: urlPar,
	dataType:"json",
	success: function(response){
		var ulctr=document.getElementById("ul_program");
		ulctr.innerHTML="";
		var result="";
		if(objaction=="program"){
			for(i=0;i<response.length-1;++i){
				result+="<li class=\"c7\"><input type=\"checkbox\" name=\"ck[]\" value=\""+response[i].id+"\" /><span class=\"hong12_f\">["+response[i].author+"]</span></li><li class=\"c1\"><a href=\"#\" class=\"hui12\">"+response[i].title+"</a> </li><li class=\"c5\"><span class=\"hui12_f\">"+response[i].timelength+"分钟</span></li><li class=\"c5\"><span class=\"hui12_f\">"+response[i].hits+"次</span></li>";
				if(response[i].flag==1){
					result+="<li class=\"c7\"><a href=\"#html\" class=\"jh12\" style=\"color:#15A953\" onclick=\"openProgram('"+objurl+"/program/play?id="+response[i].id+"')\"><strong>预览</strong></a> 　<a href=\"#html\" onclick=\"mm_addxx('"+objurl+"',"+response[i].id+")\" class=\"jh12\"><strong>添加</strong></a></li>";
				}else{
					result+="<li class=\"c7\"><a href=\"#html\" class=\"jh12\" onclick=\"openProgram('"+objurl+"/program/play?id="+response[i].id+"')\"><strong>学习</strong>（已选）</a></li>";
				}
			}
		}else{
			for(i=0;i<response.length-1;++i){
				result+="<li class=\"c6\"><span class=\"hong12_f\">["+response[i].author+"]</span></li><li class=\"c11\"><span class=\"hui12\">"+response[i].title+"</span> </li><li class=\"c5\"><span class=\"hui12_f\">"+response[i].timelength+"</span></li><li class=\"c3\"><span class=\"hui12_f\">"+response[i].hits+"次</span></li><li class=\"c3\"><a href=\""+objurl.replace('index.php',"public")+"/html/"+response[i].filename+"\" class=\"jh12\" target=\"_blank\"><strong>阅读</strong></a></li>";
			}
		}
		ulctr.innerHTML=result;
		var rcount=response[response.length-1].id;
		var pnum=parseInt(objpager);
		var psize=15;
		gethtml(objpager,pnum,rcount,psize,objurl,objtid,objaction);
		document.getElementById("hfaction").value=objaction;
		document.getElementById("hftid").value=objtid;
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//专家留言
function mm_comments(objurl,objeid,objtid,objcontent)
{
	objcontent=objcontent.replace(/\r\n/gi,"<br/>");
	var urlPar="eid=" + objeid +"&content=" + encodeURI(objcontent) +"&tid=" + objtid +"&random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/expert/comments/",
	data: urlPar,
	success: function(response){
		//alert(response);
		if(response=="-1"){
			alert("您还未登录本系统，请登录后留言！");
		}else if(response>0){
			alert("成功留言，谢谢您的支持！");
			mm_addtr(response);
		}else{
			alert("留言失败，请重试！");
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//专家支持
function mm_commentshits(objurl,objcid)
{
	var urlPar="cid=" + objcid +"&random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/expert/commenthits/",
	data: urlPar,
	success: function(response){
		//alert(response);
		if(response=="-1"){
			alert("您还未登录本系统，请登录后支持！");
		}else if(response>0){
			alert("成功支持，谢谢您的支持！");
		}else{
			alert("支持失败，请重试！");
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//回复主题
function mm_reply(objurl,objcontent,objdid,objpid)
{
	var urlPar="did=" + objdid + "&content="+ encodeURI(objcontent) +"&parentid="+ objpid +"&random=" +Math.random();
	$.ajax({
	type: "POST",
	url: objurl+"/discuzz/addreply/",
	data: urlPar,
	success: function(response){
		//alert(response);
		if(response=="1"){
			alert("回复成功，谢谢您的支持！");
			mm_replyrow();
		}else{
			alert("回复失败，请重试！");
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//支持主题
function mm_replyzhichi(objurl,objdid,objflag)
{
	var urlPar="did=" + objdid + "&flag="+ objflag +"&random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/discuzz/zhichi/",
	data: urlPar,
	success: function(response){
		//alert(response);
		if(response=="1"){
			alert("成功支持，谢谢您的支持！");
		}else{
			alert("支持失败，请重试！");
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
//关闭主题
function mm_replyclose(objurl,objdid,objflag)
{
	var urlPar="did=" + objdid + "&flag="+ objflag +"&random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/discuzz/close/",
	data: urlPar,
	success: function(response){
		//alert(response);
		if(response=="1"){
			alert("成功关闭，谢谢您的支持！");
		}else{
			alert("关闭失败，请重试！");
		}
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}
/**
*限制视屏只能在同一个窗口打开
*/
function openProgram(url){
	another=open(url,'program','height=800,width=1100,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no,status=no');
}
/**
*检测内容长度
*/
function mm_checklen(strTemp)
{
	var i,sum;
	sum=0;
	strTemp=strTemp.replace(/^(\s)*|(\s)*$/g,"");
	for(i=0;i<strTemp.length;i++)
	{
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
	}
	return sum;
}
//增加浏览量
function mm_ipflux(objurl)
{
	var urlPar="random=" +Math.random();
	$.ajax({
	type: "GET",
	url: objurl+"/news/ipflux/",
	data: urlPar,
	success: function(response){
		//alert(response);
	},
	error:function(data)
	{
		//alert(data.responseText);
	}
  });
}